predictGOOG = function(plik){
  dane = read.csv(plik, header = F, colClasses = c("character", "numeric"))
  dane = xts(dane[, 2], as.Date(dane[, 1], "%Y%m%d"))  
  T = length(dane)
  returns = diff(dane)/lag(dane)
  forecast = array(NA, T)
  for (i in 202:T){
	forecast[i] = (1 - 0.0003 -0.13*as.numeric(returns[i-7]) + 0.07*as.numeric(returns[i-8]) + 0.05*as.numeric(returns[i-4])  ) * dane[i-1]
  }
  return(cbind(dane,forecast))
}

d2 = "GOOG_2005_2006.csv"
f2 = predictGOOG(d2)
RWE2 = sum(abs(diff(f2[, 1]))[253:503])
FE2 = sum(abs(f2[253:503, 1]-f2[253:503, 2]))
print(RWE2)
print(FE2)
print(FE2/RWE2)
plot(f2[, 1], type = "l")
lines(f2[, 2], col = "red")
